package com.qfedu.service;

import com.alibaba.fastjson.JSONObject;
import com.qfedu.dao.SongDao;
import com.qfedu.entity.Song;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SongServiceImpl implements SongService{
    @Autowired
    private SongDao songDao;

    @Override
    public List<Song> findAllSong() {
        List<Song> allSong = songDao.findAllSong();
        return allSong;
    }

    @Override
    public List<Song> findSongBySingerId(int singerId) {
        List<Song> songBySingerId = songDao.findSongBySingerId(singerId);
        return songBySingerId;
    }

    @Override
    public List<Song> findSongById(int id) {
        List<Song> songById = songDao.findSongById(id);
        return songById;
    }

    @Override
    public List<Song> findSongByName(String name) {
        List<Song> songByName = songDao.findSongByName(name);
        return songByName;
    }

    @Override
    public int updateSong(Song song) {
        int i = songDao.updateSong(song);
        return i;
    }

    @Override
    public int deleteSong(int id) {
        int i = songDao.deleteSong(id);
        return i;
    }
    //更新歌曲图

    @Override
    public JSONObject updatePic(Song song) {
        int i = songDao.updatePic(song);

        JSONObject jsonObject = new JSONObject();

        if (1 != 0){
            jsonObject.put("code",1);
            jsonObject.put("msg","修改成功");
        }else {
            jsonObject.put("code",0);
            jsonObject.put("msg","修改成功");
        }
        return jsonObject;
    }

    @Override
    public JSONObject addUrl(Song song) {
        int i = songDao.addUrl(song);
        JSONObject jsonObject = new JSONObject();
        if (i != 0){
            jsonObject.put("code",1);
            jsonObject.put("msg","上传成功");
        }else {
            jsonObject.put("code",0);
            jsonObject.put("msg","上传失败");
        }
        return jsonObject;
    }

    @Override
    public JSONObject updateSongById(Song song) {
        int i = songDao.updateSongById(song);
        JSONObject jsonObject = new JSONObject();
        if (i != 0){
            jsonObject.put("code",1);
            jsonObject.put("msg","成功");
        }else {
            jsonObject.put("code",0);
            jsonObject.put("msg","失败");
        }
        return jsonObject;
    }


}
